﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.IO;

namespace CoreShop.App
{
    public class Common
    {
        public static string GetTaskID()
        {
            string ID = System.DateTime.Now.Year.ToString() + System.DateTime.Now.Month.ToString() + System.DateTime.Now.Day.ToString()+GetTaskMaxID();
            SetInfoTxt();
            return ID;
        }

        private static int GetTaskMaxID()
        {
            if (!File.Exists("info.txt"))
                CreateInfoTxt();

            string str = File.ReadAllText(@"info.txt");
            int ID = 0;
            try
            {
                ID = int.Parse(str);
            }
            catch
            {
                ID = 1;
            }
            return ID;
        }

        private static void CreateInfoTxt()
        {
            FileInfo myFile = new FileInfo(@"info.txt");
            StreamWriter sw = myFile.CreateText();
            sw.Write('1');
            sw.Close();

        }

        private static void SetInfoTxt()
        {
            int ID = GetTaskMaxID();
            File.WriteAllText(@"info.txt", (ID + 1).ToString());
        }
    }
}
